package cosw.com.shanghaica;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import java.util.List;
import java.util.Map;

/**
 * Created by Ryan on 2017/8/15.
 */

public class ContainerListViewAdapter extends BaseAdapter {

  private Context context;
  private List<Map<String, Object>> itemList;

  public ContainerListViewAdapter(Context context, List<Map<String, Object>> itemList) {
    this.context = context;
    this.itemList = itemList;
  }

  @Override
  public int getCount() {
    return itemList.size();
  }

  @Override
  public Object getItem(int position) {
    return itemList.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    ViewHolder holder;
    if (view != null) {
      holder = (ViewHolder) view.getTag();
    } else {
      view = LayoutInflater.from(context).inflate(R.layout.container_list_item, parent, false);
      holder = new ViewHolder(view);
      view.setTag(holder);
    }

    Map<String, Object> map = itemList.get(position);
    holder.title.setText((String) map.get("title"));
    return view;
  }

  static class ViewHolder {

    @BindView(R.id.tv_title)
    TextView title;

    public ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
